# Programs

set(GAME_EXE ${CMAKE_PROJECT_NAME})
set(ED_EXE ${CMAKE_PROJECT_NAME}ed)

add_executable(${GAME_EXE}
	main.cpp

	input.cpp
	audio.cpp
	video.cpp
	disk.cpp
	rand.cpp
	camera.cpp

	image.cpp
	sound.cpp
	music.cpp
	data.cpp

	grid.cpp

	stage.cpp
	cue.cpp

	actor.cpp
	player.cpp
	enemy.cpp
	weapon.cpp
	item.cpp
	door.cpp
	boat.cpp
	effect.cpp

	hud.cpp

	game.cpp
	title.cpp
	menu.cpp
	select.cpp
	gameover.cpp
	app.cpp

	cJSON.c
	SFMT.c
	)

add_executable(${ED_EXE}
	editor.cpp

	video.cpp
	disk.cpp
	camera.cpp

	image.cpp
	data.cpp

	grid.cpp

	stage.cpp
	cue.cpp

	cJSON.c
	)

set_target_properties(${GAME_EXE} PROPERTIES
	RUNTIME_OUTPUT_DIRECTORY ..
	)
set_target_properties(${ED_EXE} PROPERTIES
	RUNTIME_OUTPUT_DIRECTORY ..
	)

# Defines

if(RASPBERRYPI)
	set(DEFINES GLES RASPBERRYPI)
endif(RASPBERRYPI)

if(DEFINES)
	set_target_properties(${GAME_EXE} PROPERTIES
		COMPILE_DEFINITIONS "${DEFINES}"
		)
endif(DEFINES)

set(DEFINES ${DEFINES} SILENT)
set_target_properties(${ED_EXE} PROPERTIES
	COMPILE_DEFINITIONS "${DEFINES}"
	)

# Libraries

set(CMAKE_KNOWN_LIBS
	SDL
	SDL_image
	SDL_mixer
	PhysFS
	)
if(NOT RASPBERRYPI)
	set(CMAKE_KNOWN_LIBS
		${CMAKE_KNOWN_LIBS}
		OpenGL)
endif(NOT RASPBERRYPI)

set(CMAKE_UNKNOWN_LIBS
	gme
	)
if(RASPBERRYPI)
	set(CMAKE_UNKNOWN_LIBS
		${CMAKE_UNKNOWN_LIBS}
		OpenGLES
		VideoCore)
endif(RASPBERRYPI)

set(ALL_LIBS ${CMAKE_KNOWN_LIBS} ${CMAKE_UNKNOWN_LIBS})

foreach(LIB ${CMAKE_KNOWN_LIBS})
	find_package(${LIB} REQUIRED)
endforeach(LIB)

# Find bundled libs
# package names are PaCkAgECaSe
# project variable names are PrOjEcTCaSe_UPPERCASE 
# all other variable names are ALL_UPPERCASE
# directory and file names are all_lowercase

foreach(LIB ${CMAKE_UNKNOWN_LIBS})
#	string(TOUPPER ${LIB} LIBVAR)
	set(${LIB}_DIR .)
	find_package(${LIB} REQUIRED)
#	if(NOT ${LIBVAR}_FOUND AND WIN32)
#		string(TOLOWER ${LIB} LIBFILE)
#		set(${LIBVAR}_ONLY_RUNTIME true)
#		add_subdirectory(${LIBFILE})
#		set(${LIBVAR}_LIBRARY ${LIBFILE})
#		set(${LIBVAR}_INCLUDE_DIR
#			${${LIB}_SOURCE_DIR}
#			${${LIB}_BINARY_DIR}	# configured .h can end up here
#			)
#		link_directories(${${LIB}_BINARY_DIR})
#	endif(NOT ${LIBVAR}_FOUND AND WIN32)
endforeach(LIB)

foreach(LIB ${ALL_LIBS})
	string(TOUPPER ${LIB} LIBVAR)
	string(REPLACE "_" "" LIBVAR ${LIBVAR})
	include_directories(${${LIBVAR}_INCLUDE_DIR})
endforeach(LIB)

set(LIBRARIES 
	${SDL_LIBRARY}
	${SDLMAIN_LIBRARY}
	${SDLIMAGE_LIBRARY}
	${PHYSFS_LIBRARY}
	)

if(RASPBERRYPI)
	set (LIBRARIES ${LIBRARIES} 
		${OPENGLES_LIBRARY}
		${VIDEOCORE_LIBRARY}
		)
else(RASPBERRYPI)
	set (LIBRARIES ${LIBRARIES} 
		${OPENGL_LIBRARY}
		)
endif(RASPBERRYPI)

target_link_libraries(${GAME_EXE}
	${LIBRARIES}
	${SDLMIXER_LIBRARY}
	${GME_LIBRARY}
	)

target_link_libraries(${ED_EXE}
	${LIBRARIES}
	)

install(TARGETS ${GAME_EXE} ${ED_EXE} RUNTIME DESTINATION .)
